package com.battleship.models;

public class GameBoard {

	private static final char NOT_VALID = 'x';
	private static final char EMPTY = 'e';
	private static final char WATER = 'w';
	private static final char TOUCHED = 't';
	public static final char DESTRUCTOR = 'd';// It occupies 2 squares
	public static final char SUBMARINE = 's';// It occupies 3 squares
	public static final char CRUISER = 'c'; // It occupies 3 squares
	public static final char BATTLESHIP = 'b';// It occupies 4 squares
	public static final char CARRIER = 'r';// It occupies 5 squares
	private static final int BOARD_SIZE = 10;

	private char[][] board;

	public GameBoard() {

		board = new char[BOARD_SIZE][BOARD_SIZE];
		for (int i = 0; i < board.length; i++) {
			for (int j = 0; j < board[i].length; j++) {
				board[i][j] = WATER;
			}
		}
	}

	public void paintBoardModel() {
		for (int i = 0; i < board.length; i++) {
			for (int j = 0; j < board[i].length; j++) {
				System.out.print(" " + board[i][j]);
			}
			System.out.println("");
		}
	}

	public char shoot(int posX, int posY) {
		char objective = board[posX][posY];
		if (objective == EMPTY) {
			board[posX][posY] = WATER;
		} else if (objective == DESTRUCTOR || objective == SUBMARINE
				|| objective == CRUISER || objective == BATTLESHIP
				|| objective == CARRIER) {
			board[posX][posY] = TOUCHED;
		} else if (objective == TOUCHED || objective == WATER) {
			board[posX][posY] = NOT_VALID;
		}

		return board[posX][posY];
	}
	
	public char [][] getBoard(){
		return board;
	}

}
